<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">修改私播</h3>
                </div>
                <form id="editInfo" class="form-horizontal" role="form" onsubmit="javascript:saveInfo();">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="userName" class="col-sm-2 control-label">用户名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="userName" class="form-control" name="userName"
                                       value="${obj.userName}" placeholder="用户名称">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">内容：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="content" class="form-control" name="content"
                                       value="${obj.content}" placeholder="内容">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="userImg" class="col-sm-2 control-label">用户头像：</label>
                            <div class="col-md-8">
								<input type="file" class="file-loading" id="userImgFile" accept="image/*">
								<input type="text"  value="${obj.userImg}" class="form-control input-sm" id="userImgUrl" name="userImg"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <input type="hidden" name ="id" id="id" value="${obj.id}"/>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
$(function(){
	//用户头像上传
	   $("#userImgFile").fileinput({
	   	uploadUrl:"<%=path%>/barrageAndUser/uploadClassifyImg",
	       browseClass: "btn btn-primary",
	       enctype: 'multipart/form-data',
	       autoReplace:true,
	       dropZoneEnabled:false,
	       browseLabel: "上传",
	       showCaption: false,
	       showRemove: false,
	       showUpload: true,
	       showZoom:false,
	       maxFileCount:1, ////表示允许同时上传的最大文件个数
	       allowedFileTypes:["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
	       previewSettings:{
	       	image: {width: "auto", height: "100px"},
	       },
	   });
	   $('#userImgFile').on('fileuploaded', function(event, data, previewId, index) {
	   	var path = data.response.initialPreviewConfig[0].extra.path;
	       $("#userImgUrl").val(path);
	   });
	   $('#userImgFile').on('filedeleted', function(event,key,jqXHR,data) {
	   	if($("#userImgUrl").val()==data.path)
	   		$("#userImgUrl").val('');
	   }); 
	});
		function saveInfo(){
			var content = $("#content").val();
			var userImg = $("#userImgUrl").val();
			var userName = $("#userName").val();
			var id = $("#id").val();
			$.ajax({
				type:"post",
				async: false,
				url:"<%=path%>/barrageAndUser/alertBarrageAndUserSave",
				data:{content:content,
					userImg:userImg,
					userName:userName,
					id:id},
				dataType:"json",
				success: function(data){
					if (data.missage == "success") {
	                    modalMsg("修改成功", "success");
	                    window.parent.location.reload();
	                    var index = parent.layer.getFrameIndex(window.name);
	                    parent.layer.close(index);
	                }else if(data.missage == "error"){
	                	 modalMsg("修改失败", "error");
	                }else{
	                	 modalMsg("更新失败", "error");
	                }
				}
			});
		}
</script>
</body>
</html>